package cn.sofwin.web.blog.dao;

import cn.sofwin.core.dao.BaseDao;
import cn.sofwin.core.utils.JdbcUtils;
import cn.sofwin.web.blog.entity.ArticleComment;

import java.util.List;

/**
 * 文章评论数据访问层
 */
public class ArticleCommentDao extends BaseDao<ArticleComment> {

    @Override
    public int insert(ArticleComment comment) {
        String sql = "insert into article_comment(user_id, article_id, content, add_time) values (?, ?, ?, ?)";
        return JdbcUtils.insert(
                sql,
                comment.getUser().getId(),
                comment.getArticle().getId(),
                comment.getContent(),
                comment.getAddTime());
    }

    @Override
    public int deleteById(Integer id) {
        return JdbcUtils.update("delete from article_comment where id = ?", id);
    }


    @Override
    public int update(ArticleComment comment) {
        // TODO 评论不允许修改
        return 0;
    }

    @Override
    public ArticleComment get(Integer id) {
        //TODO 有坑
        return JdbcUtils.queryForObject(ArticleComment.class, "select * from article_comment where id = ?", id);
    }

    @Override
    public List<ArticleComment> all() {
        //TODO 有坑
        return JdbcUtils.queryForList(ArticleComment.class, "select * from article_comment");
    }
}
